package com.example.server.service.impl;

import com.example.server.mapper.ProductionMapper;
import com.example.server.pojo.Interstway;
import com.example.server.pojo.Localtion;
import com.example.server.pojo.Production;
import com.example.server.service.JdbcService;
import com.example.server.service.Productionservice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class ProductionserviceImpl implements Productionservice {
    @Resource
    ProductionMapper productionMapper;
    @Resource
    JdbcService jdbcDao;
    @Override
    public List<Interstway> getInterstway() {
        return productionMapper.getInterstway();
    }
    public java.sql.Timestamp getCurrentDate() {
        java.util.Date today = new java.util.Date();
        return new java.sql.Timestamp(today.getTime());
    }
    @Override
    public String createproduction(String p_id, String p_name, String p_createid,String p_info, int minyear, int maxyear, int limitmoney, String interstway) {
        if(productionMapper.getprodunctionbyId(p_id)==null){
            Date p_createtime =new Date();
            jdbcDao.createtable(p_id);
            productionMapper.createproduction(p_id, p_name,p_createid,getCurrentDate(),p_info,minyear,maxyear,limitmoney,interstway);
            return "创建成功";
        }else{
            return "当前产品id已存在";
        }
    }

    @Override
    public List<Production> getAllproduction() {
        return productionMapper.getAllproduction();
    }
    @Override
    public String setlocaltion(String p_id, String localinfo) {
        productionMapper.setlocaltion(p_id,localinfo);
        return "设置成功";
    }
    @Override
    public String updateproduction(String p_id, String p_name, String p_createid, String p_info, int minyear, int maxyear, int limitmoney, String interstway) {
        if(productionMapper.getprodunctionbyId(p_id)!=null){
            Date p_createtime =new Date();
            productionMapper.updateproduction(p_id, p_name,getCurrentDate(),p_info,minyear,maxyear,limitmoney,interstway);
            return "修改成功";
        }else{
            return "当前产品id不存在";
        }
    }

    @Override
    public String deleteproduction(String p_id) {
        productionMapper.deleteproduction(p_id);
        return "删除成功";
    }

    @Override
    public List<Localtion> getlocaltion() {
        return productionMapper.getlocaltion();
    }

    @Override
    public Production getprodunctionbyId(String p_id) {
        Production a=productionMapper.getprodunctionbyId(p_id);
        return a;
    }

    @Override
    public void locklimit(String p_id, int lockedlimit) {
        productionMapper.locklimit(p_id,lockedlimit);
    }

    @Override
    public void releaselimit(String p_id, int rlimit) {
        productionMapper.releaselimit(p_id,rlimit);
    }

    @Override
    public void addlimit(String p_id, int alimit) {
        productionMapper.addlimit(p_id,alimit);
    }
}
